﻿using System;
using System.Collections.Generic;
using System.Text;
using System.Text.RegularExpressions;

using Swaf;
using Swaf.BizObj;
using Swaf.BizRule;
using Swaf.Call;	
using Swaf.Scheduler;
using Swaf.Security;


namespace UserLogin
{
	public class SpecificUserScheduleTask :BaseScheduleTask
	{
		public SpecificUserScheduleTask(Match mr, object[] parms)
			:base(mr, parms)
		{
		}
		public SpecificUserScheduleTask(Match mr, string id, ICall call, object[] parms)
			:base(mr, id, call, parms)
		{
		}

		public override object fireNow()
		{
			// Ensure call isn't already running if this task is registered as a singleton
			if (IsSingleton && IsRunning)
			{
				return null;
			}

			IApplication app = null;
			Swaf.Application.currentApp = app = 
				((IAppManagement)Swaf.Application.globalApp).createSessionApplication("Scheduler:"+Id);

			IResults rc = app.ruleMgr.execute("loginAnonymousUser", null);
			rc = app.ruleMgr.execute("getUserFromUserName", "admin");
			IBizObj user = rc.CallResults as IBizObj;
			rc = app.ruleMgr.execute("loginUser", user);
			return base.fireNow();
		}
	}
}
